package com.huawei123.hasee.mynavigationview_view.Toolber_view;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Toast;

import com.huawei123.hasee.mynavigationview_view.R;

/**
 * 工具栏Toolber
 */
public class ToolberActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_toolber);
        Toolbar toolbar = (Toolbar) findViewById(R.id.mTB_toolbar);
        setSupportActionBar(toolbar);
        //设置NavigationIcon的点击事件监听，比如返回按钮。
        // app:navigationIcon="@drawable/abc"
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    /**
     * 右上角的菜单栏设置
     *
     * @param menu
     * @return
     */
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.toolber_menu, menu);
        return true;
    }

    /**
     * 右上角菜单选择条目回调，在这里处理选择后逻辑
     *
     * @param item 选择条目
     * @return
     */
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.navigation_jd) {
            Toast.makeText(this, "选中" + item.getTitle().toString(), Toast.LENGTH_SHORT).show();
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    /**
     * 收缩渐变Toolber
     * @param view
     */
    public void mBT_towToolbar(View view) {
        Intent intent = new Intent(this, TowToolberActivity.class);
        startActivity(intent);
    }

    public void mBT_threeToolbar(View view) {
        Intent intent = new Intent(this, ToolberSearchViewActivity.class);
        startActivity(intent);
    }
}
